<template>
<div>
      
</div>
</template>

<script>
export default {
  data() {
    return {};
  },
  created() {
    //生成socket对象
    var socket = new WebSocket(
        URL="ws://localhost:8000/z/test_websocket/"
    );
    socket.onopen = function () {
      console.log("WebSocket open"); //成功连接上Websocket
    };
    socket.onmessage = function (e) {
      console.log("message: " + e.data); //打印服务端返回的数据
    };
    socket.onclose = function (e) {
      console.log(e);
      socket.close(); //关闭TCP连接
    };
    if (socket.readyState == WebSocket.OPEN) {
      socket.onopen();
    }
  },
};
</script>

<style>
</style>